package com.qf.chinatelcon.apigateway.mq.listener;

import com.qf.chinatelcon.apigateway.event.ApiMapperEvent;
import com.qf.chinatelcon.apigateway.event.GrayReleaseEvent;
import com.qf.chinatelcon.apigateway.event.PublicParamsEvent;
import com.qianfeng.smsplatform.common.constants.RabbitMqConsants;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.annotation.StreamListener;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

@Component
public class LocalCacheChangeListener {

    private ApplicationContext context;

    @Autowired
    public void setContext(ApplicationContext context) {
        this.context = context;
    }

    @StreamListener(RabbitMqConsants.TOPIC_APIMAPPING_UPDATE)
    public void onApiMappingMessage(String message){
        System.err.println("收到api映射更新的消息了");
        context.publishEvent(new ApiMapperEvent());
    }

    @StreamListener(RabbitMqConsants.TOPIC_PUBLICPARAMS_UPDATE)
    public void onPublicParamsMessage(String message){
        System.err.println("收到public的更新映射消息了");
        context.publishEvent(new PublicParamsEvent());
    }

    @StreamListener(RabbitMqConsants.TOPIC_GRAYRELEASE_UPDATE)
    public void onGrayReleaseMessage(String message){
        System.err.println("收到灰度发布映射消息了");
        context.publishEvent(new GrayReleaseEvent());
    }
}
